package com.afsadmedia.pregnancy;

import java.util.ArrayList;
import java.util.List;

import com.actionbarsherlock.app.SherlockActivity;
import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuItem;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.ListView;
import android.widget.AdapterView.OnItemLongClickListener;

public class Symptoms extends SherlockActivity{
	
	
	List<ListItem> rowItems;
	 CustomListViewAdapter adapter;
	 
	ListView listView;
	
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.symptoms);
		
		
			
			
			
			rowItems = new ArrayList<ListItem>();
			for (int i = 0; i < Constants.selectSymptoms.size(); i++) {

				ListItem item1 = new ListItem(Constants.selectSymptoms.get(i), null);

				rowItems.add(item1);
			}

			listView = (ListView) findViewById(R.id.listView_weightmanagemnt_symptoms);
			
			adapter = new CustomListViewAdapter(getApplicationContext(), R.layout.listitem,
					rowItems);
			listView.setAdapter(adapter);
			
			
			listView.setOnItemLongClickListener(new OnItemLongClickListener() {

				@Override
				public boolean onItemLongClick(AdapterView<?> arg0, View arg1,
						int position, long arg3) {
					// TODO Auto-generated method stub

					AlertDialog.Builder adb = new AlertDialog.Builder(Symptoms.this);
					adb.setTitle("Delete?");
					adb.setMessage("Are you sure you want to delete the Selected Entery."
							);

					final int positionToRemove = position;

					adb.setNegativeButton("Cancel", null);
					adb.setPositiveButton("Ok", new AlertDialog.OnClickListener() {
						public void onClick(DialogInterface dialog, int which) {
						
							Constants.selectSymptoms.remove(positionToRemove);
						
							
							adapter.notifyDataSetChanged();

							listView.setAdapter(adapter);
							listView.invalidateViews();

							Intent i = new Intent(Symptoms.this, Symptoms.class);
							startActivity(i);
						}
					});
					adb.show();

				
					return true;
				}
			});
			
			
			
			
	}
	
	
	
	public boolean onCreateOptionsMenu(com.actionbarsherlock.view.Menu menu) 
	{
		getSupportActionBar().setBackgroundDrawable(
				getResources().getDrawable(R.drawable.actionbar_background)); 
		getSupportActionBar().setTitle("Favorite");
		getSupportActionBar().setDisplayHomeAsUpEnabled(true);
		getSupportActionBar().setHomeButtonEnabled(true);
		
	
		menu.add(Menu.NONE, R.id.add, Menu.NONE,R.string.toggle_show_home)
	    .setIcon(R.drawable.addicon)
	    .setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
		
	    return super.onCreateOptionsMenu(menu);
 
    }
	
	
	
	public boolean onOptionsItemSelected(com.actionbarsherlock.view.MenuItem item) {
	    switch(item.getItemId()){
	    
	    case android.R.id.home:
	    	
//			Intent in=new Intent(Details.this,FavItems.class);
//			in.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
//			startActivity(in);
    	
        return true;
	   
	    case R.id.add:
	    	
	    	Intent i = new Intent(Symptoms.this,SympotomsListview.class);
     		startActivity(i);
	        return true;
	    default:
	        return false;
	    }
	}
	
	
	
	
	
	
    @Override
    public void onBackPressed() {
    	// TODO Auto-generated method stub
    	 Intent i = new Intent(getApplicationContext(),Listview.class);
         startActivity(i);
    	super.onBackPressed();
    }

}
